import open3d as o3d
import numpy as np

cloud = o3d.io.read_point_cloud("../datasets/standford_cloud_data/China dragon.pcd", print_progress=True)
pts = np.asarray(cloud.points)
# 根据高度生成色彩
colors = np.zeros([pts.shape[0], 3])
height_max = np.max(pts[:, 2])
height_min = np.min(pts[:, 2])
delta_c = abs(height_max - height_min) / (255 * 2)
for j in range(pts.shape[0]):
    color_n = (pts[j, 2] - height_min) / delta_c
    if color_n <= 255:
        colors[j, :] = [0, 1 - color_n / 255, 1]
    else:
        colors[j, :] = [(color_n - 255) / 255, 0, 1]

cloud.colors = o3d.utility.Vector3dVector(colors)
o3d.visualization.draw_geometries([cloud],width=720,height=720)
